<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <!-- 搜索 -->
        <label class="el-form-item-label">通知或者处理人</label>
        <el-input v-model="query.userId" clearable placeholder="通知或者处理人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />

        <label class="el-form-item-label">类型</label>
        <el-select v-model="query.type" clearable size="small" placeholder="类型" class="filter-item" style="width: 90px" @change="crud.toQuery">
          <el-option v-for="item in dict.sys_notice" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <label class="el-form-item-label">处理情况</label>

        <el-select v-model="query.isNotice" clearable size="small" placeholder="处理情况" class="filter-item" style="width: 90px" @change="crud.toQuery">
          <el-option v-for="item in dict.notice_is" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="id">
            <el-input v-model="form.id" />
          </el-form-item>
          <el-form-item label="标题">
            <el-input v-model="form.title" />
          </el-form-item>
          <el-form-item label="通知或者单位">
            <el-input v-model="form.deptName" />
          </el-form-item>
          <el-form-item label="处理类型">
            <el-input v-model="form.type" />
          </el-form-item>
          <el-form-item label="路径">
            <el-input v-model="form.url" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column label="标题">
          <template slot-scope="scope">
            <span style="color: #1890ff;cursor: pointer;" @click="tolink(scope.row)">{{ scope.row.title }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="user" label="单位">
          <template slot-scope="scope">
            <span>{{ scope.row.dept&&scope.row.dept.name }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="type" label="处理类型">
          <template slot-scope="scope">
            {{ dict.label.sys_notice[scope.row.type] }}
          </template>
        </el-table-column>

        <el-table-column prop="isNotice" label="处理情况">
          <template slot-scope="scope">
            {{ dict.label.notice_is[scope.row.isNotice] }}
          </template>
        </el-table-column>

        <el-table-column v-permission="['admin','tSysNotice:edit','tSysNotice:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudTSysNotice from '@/api/system/tSysNotice'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import { getUser } from '@/api/system/user'
const defaultForm = { id: null, title: null, userId: null, type: null, url: null }
export default {
  name: 'TSysNotice',
  components: { pagination, crudOperation, rrOperation, udOperation },
  dicts: ['sys_notice', 'notice_is'],
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'system/', url: 'api/tSysNotice', idField: 'id', sort: 'id,desc', crudMethod: { ...crudTSysNotice }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'tSysNotice:add'],
        edit: ['admin', 'tSysNotice:edit'],
        del: ['admin', 'tSysNotice:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'userId', display_name: '通知或者处理人' },
        { key: 'type', display_name: '类型（1.待办，2待阅）' }
      ]
    }
  },
  created() {
    this.crud.optShow = {
      add: false,
      edit: false,
      del: false,
      download: true
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    loadUsers() {
      getUser().then(res => {
        const date = res.content
        this.buildDepts(date)
        this.depts = date
      })
    },
    tolink(item) {
      location.replace(item.url)
    }
  }
}
</script>
<style scoped>
</style>
